<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini"  onload="checkBrowser()">
<section class="content-header">
    <h1 style="display: inline-block">
        批量库存划项目标记导入
    </h1>
    <button onclick="javascript:location.href='/purchase/invPro/index'" type="button" class="btn btn-success"
            style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:14%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
        <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
           class="glyphicon glyphicon-share-alt"></i><span
            style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回到库存划项目申请页面</span>
    </button>
</section>
<section class="content">
    <form id="form">
        <div class="row">
            <div class="col-md-6 col-md-offset-3">
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">Excel信息导入</h3>
                    </div>
                    <div class="box-body">
                        <div class="form-group">
                            <a id="stockExport" href="/purchase/invPro/exportPage">点击跳转到模板导出页面</a>
                        </div>
                        <div class="form-group">
                            <label>7天内导入错误数据</label>
                            <a id="download-error" shiro:haspermission="purinv:purchalist:edit" th:href="@{/purchase/change/errorExport/{userId}(userId=${userId})}">点击下载</a>
                            <p class="help-block">如果错误数据已经处理，请忽略！</p>
                        </div>
                        <div class="form-group">
                            <a th:href="@{/file/外购件串料或库存划项目模板.xlsx}">
                                点击下载导入模板
                            </a>
                        </div>
                        <div class="form-group">
                            <label for="upload_file">选择Excel文件并上传</label>
                            <input type="file" multiple="multiple" shiro:haspermission="purinv:purchalist:edit" id="upload_file" name="file">

                            <p class="help-block">上传文档从第二行开始导入，请按格式要求整理，有‘禁改’,‘勿动’字样列的信息不允许修改，否则将导致导入失败！</p>
                        </div>
                    </div>
                    <div class="box-footer">
                        <p class="text-red">只导入标记数据且导入之前请确认导入信息准确无误！</p>
                        <button shiro:haspermission="purinv:purchalist:edit" id="btn-upload" type="button" class="btn btn-primary" style="width: 82px;height: 35px;">上传</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">


    function checkBrowserFun() {
        let is360 = false;
        let isIE = false;
        let isFirefox = false;
        let isChrome = false;
        let isEdge = false;
        let broName = 'Runing';
        let str = '';
        let strStart = 0;
        let strStop = 0;
        let arr = new Array();
        let temp = '';
        let userAgent = window.navigator.userAgent; //包含以下属性中所有或一部分的字符串：appCodeName,appName,appVersion,language,platform
        /*alert(userAgent);*/
        //FireFox
        if (userAgent.indexOf('Firefox') != -1) {
            isFireFox = true;
            /*broName = 'FireFox浏览器';*/
            strStart = userAgent.indexOf('Firefox');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号')

        }
        //Edge
        if (userAgent.indexOf('Edge') != -1) {
            isEdge = true;
            /*broName = 'Edge浏览器';*/
            strStart = userAgent.indexOf('Edge');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号');
        }
        //IE浏览器
        if (userAgent.indexOf('NET') != -1 && userAgent.indexOf("rv") != -1) {
            isIE = true;
            /*broName = 'IE浏览器'; */
            strStart = userAgent.indexOf('rv');
            strStop = userAgent.indexOf(')');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('rv', 'IE').replace(':', '版本号');
        }
        //360极速模式可以区分360安全浏览器和360极速浏览器
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") < 0 && userAgent.indexOf("Firefox") < 0) {
            if (navigator.javaEnabled()) {
                is360 = true;
                broName = '360安全浏览器-极速模式';
            } else {
                is360 = true;
                broName = '360极速浏览器-极速模式';
            }
        }
        //360兼容
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") != -1 && userAgent.indexOf("MSIE") != -1 && userAgent.indexOf("rv") < 0) {
            is360 = true;
            broName = '360兼容模式';
        }
        //Chrome浏览器
        if (userAgent.indexOf('WOW') < 0 && userAgent.indexOf('Chrome') > 0 && userAgent.indexOf("Edg") < 0) {
            isChrome = true;
            /*broName = 'Chrome浏览器';*/
            strStart = userAgent.indexOf('Chrome');
            strStop = userAgent.indexOf(' Safari');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('/', '版本号');
        }
        return isChrome;
    }

    /**
     * 检测浏览器
     * */
    function checkBrowser(){
        if(!checkBrowserFun()){
            alert("尊敬的客户，您使用浏览器不是谷歌浏览器，请使用谷歌浏览器访问本系统！");
            location.href=ctx+"overview/index";
        }
    }

    /** 验证 */
    js.validate.init("form", {
        fields: {
            file: {
                validators: {
                    notEmpty: {message: '上传文件不能为空'},
                    file: {extension: 'xls,xlsx', message: '请选择excel文件'}
                }
            }
        }
    });
    $(function () {
        $("title").html($("title").html()+" —— 批量库存划项目标记导入");
    })

    /** 上传文件 */
    $("#btn-upload").click(function () {
        js.validSubmit({
            formId: "form",
            url: ctx + "purchase/invPro/importExcel",
            data: new FormData($("#form")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.alert(result.msg);
                } else {
                    js.modal.alert("部分数据导入失败，请下载错误数据。");
                }
                js.modal.closeLoading();
            },
            error: function () {
                js.modal.alert("部分数据导入失败，请下载错误数据。");
                js.modal.closeLoading();
            }
        });
    });

</script>
</body>
</html>
